package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.common.CommonResult;
import com.neuedu.yyzx.entity.NurseRecords;
import com.neuedu.yyzx.service.INurseRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("//nurseRecords")
public class NurseRecordsController {

    @Autowired
    INurseRecordsService nurseRecordsService;
    @RequestMapping("/list")
    CommonResult list(Page page , NurseRecords nurseRecords){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_deleted",0);

        if(nurseRecords!=null && StringUtils.isNotEmpty(nurseRecords.getCustomerName())){
            queryWrapper.like("customer_name",nurseRecords.getCustomerName());
        }
        return CommonResult.success(nurseRecordsService.page(page,queryWrapper));
    }

    @RequestMapping("/add")
    CommonResult add(NurseRecords nurseRecords){
        return CommonResult.success(nurseRecordsService.saveOrUpdate(nurseRecords));
    }

    @RequestMapping("/update")
    CommonResult update(NurseRecords nurseRecords){
        return CommonResult.success(nurseRecordsService.updateAll(nurseRecords));
    }

    @RequestMapping("/getById")
    CommonResult getById(Integer id){
        return CommonResult.success(nurseRecordsService.getById(id));
    }

    @RequestMapping("/del")
    CommonResult del(Integer id){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.set("is_deleted",1);
        updateWrapper.eq("id",id);
        return CommonResult.success(nurseRecordsService.update(updateWrapper));
    }

}
